﻿// Copyright Microsoft

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Microsoft.Samples.SqlServer.Common
{
  /// <summary>
  /// Interaction logic for NotesUserControl.xaml
  /// </summary>
  public partial class NotesUserControl : UserControl
  {
    public NotesUserControl()
    {
        InitializeComponent();
    }

    private void richTextBox_ContextMenuOpening(object sender, ContextMenuEventArgs e)
    {
        int width = 150;

        richTextBox.ContextMenu.Width = width;

        //Set width to size of control. A popup outside the control sends event message to Word or Excel
        if (richTextBox.ViewportWidth < width)
        {
            richTextBox.ContextMenu.Width = richTextBox.ViewportWidth;
        }
        if ((richTextBox.ViewportWidth - e.CursorLeft) < richTextBox.ContextMenu.Width)
            if (e.CursorLeft < richTextBox.ContextMenu.Width)
            {
                richTextBox.ContextMenu.HorizontalOffset = richTextBox.ContextMenu.Width - e.CursorLeft;
            }
    }

  }
}
